<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<div class="row">
	<div class="col-md-12">
		<div class="class-name"></div>
	</div>
</div>
<div class="row">
	<div class="col-md-1"></div>
	<div class="col-md-10">
		<div class="form-group">
			<div class="row">
				<div class="col-md-12" style="text-align:right;">
					<shiro:hasRole name="teacher">
						<button class="btn btn-primary" id="studentDelete">删除</button>
						<button class="btn btn-primary" id="add-bigclass-stu">添加学生</button>
						<button class="btn btn-primary" id="upload-student-file">导入学生名单</button>
					</shiro:hasRole>
				</div>
			</div>
		</div>
	</div>
	<div class="col-md-1"></div>
</div>
<div class="row">
	<div class="col-md-1"></div>
	<div class="col-md-10">
		<table class="table table-hover">
			<thead>
				<tr>
					<th>序号</th>
					<th>学号</th>
					<th>姓名</th>
					<shiro:hasRole name="teacher">
						<th><input type="checkbox" name="" id="checkAll" value="" />全选</th>
					</shiro:hasRole>
				</tr>
			</thead>
			<shiro:hasRole name="teacher">
				<tbody id="studentListTeacher">
				</tbody>
			</shiro:hasRole>
			<shiro:hasRole name="assistant">
				<tbody id="studentListAssistant">
				</tbody>
			</shiro:hasRole>
		</table>
	</div>
	<div class="col-md-1"></div>
</div>
<div class="row">
<%--	<div class="col-md-1"></div>--%>
<%--	<div class="col-md-5" style="text-align:left;">--%>
<%--		<shiro:hasRole name="teacher">--%>
<%--			<button class="btn btn-primary" id="studentDelete">删除</button>--%>
<%--		</shiro:hasRole>--%>
<%--	</div>--%>
	<div class="col-md-12" style="text-align:center;">
		<div class="page-content" id="bigStudentPage">
			<nav class="pagination" role="navigation" style="text-align:center;">
				<a class="last-page" id="last-page-has-big">
					<i class="fa fa-angle-left"></i>
				</a>
				<span class="page-number" id="page-number-has-big">第1页/共7页</span>
				<a class="next-page" id="next-page-has-big">
					<i class="fa fa-angle-right"></i>
				</a>
			</nav>
		</div>
	</div>
	<div style="height: 100px;"></div>
</div>

<script>

$(function() {
	$("#studentDelete").click(studentDelete);
	$("#upload-student-file").click(function() {
		var index = layer.open({
			type: 1,
			title: '导入学生名单',
			fixed: false, //不固定
			maxmin: true,
			closeBtn: 1,
			area: ['80rem', '40rem'],
			content: $("#upload-student-page"),
			end: function() {
				window.location.reload();
            }
		});
		layer.full(index);
	});
	$("#add-bigclass-stu").click(function(){
		layer.open({
			type: 1,
			title: '添加学生',
			fixed: false, //不固定
			maxmin: true,
			closeBtn: 1,
			skin: 'layui-layer-molv',
			area: ['80rem', '40rem'],
			content: $(".addstu-bigclass"),
			end: function() {
				$(".addstu-bigclass").css("display","none");
				$("input[name='searchStudent']").val("");
				window.location.reload();
            }
		});
	});
	
	$("#checkAll").click(function(){
		//全选状态
		if($("#checkAll").is(':checked')){
			$('input[name="deleteStudentId"]').each(function(){
				$(this).prop("checked", true);
			});
		}else{//全不选状态
			$('input[name="deleteStudentId"]').each(function(){
				$(this).prop("checked", false);
			});
		}
	});
});
var initStudentList = function(){
	$("#className").text(data.data.classView.className+"学生列表");
	$(".class-name").text(data.data.classView.className);
	var studentListTeacher = $("#studentListTeacher");
	var studentListAssistant = $("#studentListAssistant");
	studentListTeacher.empty();
	studentListAssistant.empty();
	var s0="";
	var s1="";
	var students=data.data.students;

	for(var i=0;i<students.length;i++){
		console.log(data)
		var item=students[i];
		s0+="<tr>";
		s0+="<th scope=\"row\">"+((data.data.pageNo-1)*10+i+1)+"</th>";
		s0+="<td title=\""+item.studentCode+"\">"+item.studentCode+"</td>";
		s0+="<td title=\""+item.name+"\">"+item.name+"</td>";
		s0+="<td><input type=\"checkbox\" name=\"deleteStudentId\" value=\""+item.id+"\" /></td>";
		s0+="</tr>";
	}
	for(var i=0;i<students.length;i++){
		var item=students[i];
		s1+="<tr>";
		s1+="<th scope=\"row\">"+((data.data.pageNo-1)*10+i+1)+"</th>";
		s1+="<td title=\""+item.studentCode+"\">"+item.studentCode+"</td>";
		s1+="<td title=\""+item.name+"\">"+item.name+"</td>";
		s1+="</tr>";
	}
	studentListTeacher.append(s0);
	studentListAssistant.append(s1);
	initBigClassPages(data.data.pageNo,data.data.allpages);
}
var initBigClassPages = function(pageNo,allpages){
	var id= ${param.id}//id="smallStudentPage"
	var lastPageObj=$("#last-page-has-big");
	var nextPageObj=$("#next-page-has-big");
	var pageNumberObj=$("#page-number-has-big");
	var lastPage=pageNo-1;
	if(lastPage<=0){//设置disableed
		lastPage=1;
		lastPageObj.removeAttr("href");
	}else{
		lastPageObj.attr("href","<c:url value='/cscontrol/listView?id="+id+"&pageNo="+lastPage+"'/>");
	}
	var nextPage = pageNo+1;
	if(nextPage>allpages){
		nextPage=allpages;
		nextPageObj.removeAttr("href");
	}else{
		nextPageObj.attr("href","<c:url value='/cscontrol/listView?id="+id+"&pageNo="+nextPage+"'/>");
	}
	if(allpages <=1){
		$("#bigStudentPage").hide();
	}else {
		$("#bigStudentPage").show();
		pageNumberObj.text("第"+pageNo+"页/共"+allpages+"页");
	}
}
var studentDelete = function(){
	var classId=data.data.classView.id;
	var studentIds =[];
	$('input[name="deleteStudentId"]:checked').each(function(){ 
		studentIds.push($(this).val()); 
	});
	if(studentIds.length<=0){
		layer.alert("请选择待删除学生");
		return ;
	}
	var json={
			ids:studentIds,
			keyId:classId
	};
	$.post(CONTEXT_PATH+"cscontrol/batchDelete", {
		data : JSON.stringify(json)
	}, function(data) {
		if(data.status=="success"){
			window.location.reload();
		}else{
			layer.alert(data.message);
		}
	});
}
</script>